package com.hmall.item.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.ItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/item")
@Slf4j
public class ItemContorller {

    @Autowired
    private ItemService itemService;

    @GetMapping("/list")
    public PageDTO<Item> itemList(@RequestParam("page") Integer page,
                                  @RequestParam("size") Integer size){

        return itemService.selectItem(page,size);
    }

    @GetMapping( "/{id}")
    public Item queryItemByid(@PathVariable("id") Long id){

        return itemService.queryItemByid(id);
    }


    @PostMapping("")
    public void inserterItem(@RequestBody Item item){

        itemService.insertItem(item);

    }

    @PutMapping("/status/{id}/{status}")
    public void updataItem(@PathVariable("id") Long id,
                           @PathVariable("status") Integer status){

        itemService.updateItem(id,status);
    }

    @PutMapping("")
    public void upDateItem(@RequestBody Item item){
        itemService.upDateItem(item);
    }

    @DeleteMapping("/{id}")
    public void deleteItem(@PathVariable("id") Long id){

        itemService.deleteItem(id);
    }


    @PutMapping("/stock/{itemId}/{num}")
    public void inventory(@PathVariable("itemId") Long itemId,
                          @PathVariable("num") Integer num){
        itemService.jianInventory(itemId,num);
    }


}
